export function formatTime(time) {
  // 格式化
  let hours = Math.floor(time / 1000 / 60 / 60);
  time -= hours * 60 * 60 * 1000;
  hours %= 24;
  let mins = Math.floor(time / 1000 / 60);
  time -= mins * 60 * 1000;
  let secs = Math.floor(time / 1000);
  time -= mins * 1000;
  //let mss = remainTick
  let result =
    (hours ? `${hours}时` : "") +
    (hours || mins ? `${mins}分` : "") +
    `${secs}秒`;
  return result;
}

export function tickToDate(tick, separator = "/") {
  var date = new Date(tick)
  return date.toLocaleDateString().replace(/\//, separator)
}

export function tickToTime(tick, separator = ":") {
  var date = new Date(tick)
  return date.toTimeString().slice(0, 8).replace(/:/, separator)
}

export function tickToDateTime(tick, separator = " ") {
  return tickToDate(tick) + separator + tickToTime(tick)
}

// 下载utf-8文件
export function downloadFile(data, filename){
  // 构造blob
  let blob = new Blob(
    [
      new Uint8Array([0xEF, 0xBB, 0xBF]), // UTF-8 BOM
      data
    ],
    { type: "text/plain;charset=utf-8" }
  );
  // 下载
  let pom = document.createElement('a')
  pom.href = window.URL.createObjectURL(blob)
  pom.setAttribute('download', filename)
  pom.click()
}